<template>
  <div>
    <div class="toolbar">
      <el-form :inline="true" :model="q" size="mini">

        <el-form-item label="时间:">
          <el-date-picker v-model="q.day_start" value-format="yyyy-MM-dd" type="date" placeholder="选择日期时间">
          </el-date-picker>
          <span>-</span>
          <el-date-picker v-model="q.day_end" value-format="yyyy-MM-dd" type="date" placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="问题类型:">
          <el-select v-model="q.type_id" clearable placeholder="请选择">
            <el-option label="所有" :value=null></el-option>
            <el-option v-for="item in problemsTypeList" :key="item.id" :label="item.desc" :value="item.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="二级分类:">
          <el-select v-model="q.second_type" clearable placeholder="请选择">
            <el-option label="所有" :value=null></el-option>
            <el-option v-for="(item,index) in secondList_type" :key="index" :label="item.lab" :value="item.val">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="三级分类:">
          <el-select v-model="q.third_type" clearable placeholder="请选择">
            <el-option label="所有" :value=null></el-option>
            <el-option v-for="(item,index) in thridList_type" :key="index" :label="item.lab" :value="item.val">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="query">查询</el-button>
          <el-button type="danger" @click="reload">重置</el-button>
          <el-button size="mini" @click="downloadData" type="primary" icon="el-icon-download">导出数据</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="DataTtl" size="mini" stripe border fit highlight-current-row>
      <el-table-column width="100">总计</el-table-column>
      <el-table-column prop="ttl_count" label="反馈数量" min-width="80"></el-table-column>
      <el-table-column prop="ttl_finish_count" label="已处理数量" min-width="80"></el-table-column>
      <el-table-column prop="ttl_wait_count" label="待处理数量" min-width="80"></el-table-column>
      <!-- <el-table-column prop="ttl_solved_count" label="已解决数量" min-width="80"></el-table-column> -->
      <!-- <el-table-column prop="ttl_unsolved_count" label="未解决数量" min-width="80"></el-table-column> -->
      <el-table-column prop="ttl_quality_pass_count" label="质检合格数量" min-width="90"></el-table-column>
      <el-table-column prop="ttl_quality_unpass_count" label="质检不合格数量" min-width="100"></el-table-column>

    </el-table>
    <br />
    <el-table class="el-calendar-table" :data="listData.items" v-loading.body="listLoading" size="mini" stripe border
      fit highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column min-width="100" prop="day" label="日期">
      </el-table-column>
      <el-table-column width="90" prop="type.desc" label="问题类型">
      </el-table-column>

      <el-table-column min-width="150" prop="second_type" label="二级分类">
      </el-table-column>
      <el-table-column min-width="150" prop="third_type" label="三级分类">
      </el-table-column>
      <el-table-column min-width="90" prop="total_count" label="反馈次数">
      </el-table-column>
      <el-table-column min-width="90" prop="finish_count" label="已处理数量">
      </el-table-column>
      <el-table-column min-width="90" prop="wait_count" label="待处理数量">
      </el-table-column>
      <!-- <el-table-column width="90" prop="solved_count" label="已解决数量">
      </el-table-column>

      <el-table-column width="90" prop="unsolved_count" label="未解决数量">
      </el-table-column> -->
      <el-table-column min-width="100" prop="quality_pass_count" label="质检合格数量">
      </el-table-column>
      <el-table-column min-width="110" prop="quality_unpass_count" label="质检不合格数量">
      </el-table-column>

    </el-table>
    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="q.page_no"
        :page-sizes="$store.state.app.pageSizeArr" :page-size="q.page_size"
        layout="total, sizes, prev, pager, next, jumper" :total="listData.total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getReportList, getProblemsList, getReportTTlList, getReportDownLoad } from '@/api'
import { queryFilter } from "@/utils/patch";

export default {
  name: "index",
  data () {
    return {
      show_id: null,
      listData: {},
      q: { page_size: 30, page_no: 1 },
      listLoading: false,
      showUpdate: false,
      problemsTypeList: [],
      Timetype: true,
      working: true,
      DataTtl: [],
      secondList_type: [],
      thridList_type: [],

    }
  },
  created () {
    this.getList()
    this.getProblemsList()
  },
  methods: {
    downloadData () {
      let queryObj = queryFilter(this.q)
      let data = Object.assign({}, queryObj, { to_export_file: true })
      getReportDownLoad(data).then(res => {
        if (res.status === 0) {
          window.location.href = window.location.origin + res.data.url
        }
      })
    },
    getProblemsList () {
      getProblemsList().then(res => {
        if (res.status === 0) {
          this.problemsTypeList = res.data.items
        }
      })
    },
    Details (row) {
      this.show_id = row.id
      this.showUpdate = true
    },
    // sendMsg (row) {

    // },
    query () {
      this.q = Object.assign(this.q, { page_no: 1, page_size: 30 })
      this.getList()
    },
    reload () {
      this.q = { page_no: 1, page_size: 30 }
      this.getList()
    },
    handleSizeChange (val) {
      this.q.page_size = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.q.page_no = val
      this.getList()
    },

    getList () {
      let queryObj = queryFilter(this.q)
      this.listLoading = true
      getReportList(queryObj).then(res => {
        if (res.status === 0) {
          this.listLoading = false
          this.listData = res.data
        }
      })

      getReportTTlList(queryObj).then(res => {
        if (res.status === 0) {
          this.listLoading = false
          this.DataTtl = [res.data]

        }
      })

    },
    handleSelectionChange (sel) {
      console.log(sel)
    },
    toggleTimetype () {
      if (this.Timetype) {
        delete this.q.created_at_begin
        delete this.q.created_at_end
        this.Timetype = !this.Timetype
      } else {
        delete this.q.updated_at_begin
        delete this.q.updated_at_end
        this.Timetype = !this.Timetype
      }
    },
  },
  watch: {
    showUpdate () {
      if (!this.showUpdate) {
        this.getList()
      }
    },
    'q.type_id': function () {
      if (this.q.type_id === 1) {
        delete this.q.second_type;
        delete this.q.third_type;
      } else if (this.q.type_id === 2) {
        this.secondList_type = this.$store.state.app.withDrawProblemType
        this.thridList_type = [];
        delete this.q.second_type;
        delete this.q.third_type;
      } else if (this.q.type_id === 3) {
        this.secondList_type = this.$store.state.app.accountProblemType
        this.thridList_type = [];
        delete this.q.second_type;
        delete this.q.third_type;
      } else if (this.q.type_id === 4) {
        this.secondList_type = this.$store.state.app.gameProblemType;
        this.thridList_type = this.$store.state.app.gameProblemNextType;
        delete this.q.second_type;
        delete this.q.third_type;
      } else if (this.q.type_id === 5) {
        this.secondList_type = [];
        this.thridList_type = [];
        delete this.q.second_type;
        delete this.q.third_type;
      } else if (this.q.type_id === 6) {
        this.secondList_type = this.$store.state.app.otherProblemType
        this.thridList_type = [];
        delete this.q.second_type;
        delete this.q.third_type;
      } else {
        this.secondList_type = [];
        this.thridList_type = [];
        delete this.q.second_type;
        delete this.q.third_type;
      }
    }
  }
}
</script>

<style scoped>
.el-form-item__label {
  width: 100px !important;
}
</style>
